Advertisement
Guest User

Basic While Loop

a guest
Mar 30th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | None | 0 0
  1. using System;
  2.                    
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         //A while loop keeps looping "WHILE" something is true
  8.         //Keep looping while the user doesn't say quit
  9.         //OR keep looping if the answer isn't right
  10.    
  11.         string answer = "hello";
  12.        
  13.         while(answer != "quit")
  14.         {
  15.             Console.WriteLine("Type 'quit' to exit, or type anything else to continue");
  16.             answer = Console.ReadLine();
  17.            
  18.         }
  19.        
  20.        
  21.         Console.WriteLine("Quitting the program...");
  22.        
  23.        
  24.        
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement