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

 
Participant
1 year, 1 month ago.

  • Author
    Posts
  • #79148

    Participant
    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

    Keymaster
    Points: 7
    Rank: Member

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

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

  • #79154

    Participant
    Points: 9
    Rank: Member

    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

    Participant
    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.