Empty Begin and End Blocks

Welcome Forums General PowerShell Q&A Empty Begin and End Blocks

This topic contains 3 replies, has 3 voices, and was last updated by

1 year, 4 months ago.

  • Author
  • #79148

    Points: 0
    Rank: Member

    If I have nothing to put into begin and end blocks because i have no one-time initialization or cleanup code to run. Can I define a process block without a begin and end block or will it process like a single end block? If it works correctly, from a styling and readability view point, whats better, defining empty blocks or removing them?

  • #79150

    Points: 1,759
    Helping HandTeam Member
    Rank: Community Hero

    You can omit Begin and End. Process will still act as Process.

    I personally prefer to define empty ones and do so habitually.

  • #79154

    Points: 399
    Helping Hand
    Rank: Contributor

    Without to trying to be a smart ass but why don't you just try it? Sometimes or actually really often it's appropriate to do your own sience. If it works and does the job – it's fine. 😉

  • #79166

    Points: 0
    Rank: Member

    Thanks Don.

    Olaf, I did try it but wasnt sure if my test was valid. If you dont specify any block its my understanding that it acts as one end block. Would still work but it wouldnt be optimal as it wouldnt pass on through the pipeline until complete. So i wasnt sure if my experiment was working optimally or not

The topic ‘Empty Begin and End Blocks’ is closed to new replies.