title: How to replicate do while in go?
body: <p>I want a set of code to be executed until user explicitly wants to exit the function. For eg: when a user runs the program, he will see 2 options:</p>
  
  <ol>
  <li>Run again   </li>
  <li>Exit</li>
  </ol>
  
  <p>this will be achieved using switch case structure. Here if user presses 1, set of functions associated with 1 will execute and if user presses 2, the program will exit. How should i achieve this scenario in golang ? In java, i believe this could be done using do while structure but go doesn't support do while loop. Following is my code which i tried but this goes in a infinite loop:</p>
  
  <pre><code>func sample() {
      var i = 1
      for i &gt; 0 {
          fmt.Println("Press 1 to run")
          fmt.Println("Press 2 to exit")
          var input string
          inpt, _ := fmt.Scanln(&amp;input)
          switch inpt {
          case 1:
              fmt.Println("hi")
          case 2:
              os.Exit(2)
          default:
              fmt.Println("def")
          }
      }
  }
  </code></pre>
  
  <p>The program irrespective of the input, prints only "hi". Could someone please correct me what wrong i am doing here ?</p>
  
  <p>Thanks.</p>