+ 4

While/if/ loops help

I know that this is a really general question and my apologies but i am just learning to code and some of these concepts are really easy to grasp and some... i get stuck on so bad and i dont know if im not understanding loops or just not understanding how to incorporate prior information into these loops. But i would love any tips tricks or any information and assistance that can be offered.

27th Oct 2020, 5:38 PM
Da SplitUpNinja
Da SplitUpNinja - avatar
14 Answers
+ 4
While statement is a little similar to the if statement. 1. When program reaches a while statement, it checks the boolean value in the parentheses ( ). 2. If the boolean value is True, while statement will run the code on the curly braces { }. The while loop will repeat 1. and 2. until the boolean value will become False or a special statement break is reached.
27th Oct 2020, 8:19 PM
Seb TheS
Seb TheS - avatar
+ 9
It's all about yes or no questions. Boolean is just a fancy word to substitute that. It can true or false, yes or no, 1 or 0. You get the point. When there's such a "question" in code YES will execute a statement or a block of code you have dedicated to it. Otherwise your program will skip to the next section. In a while loop you need to set a variable to define how many times you want to ask a question before going forward. A condition to stop the loop can be used inside. Otherwise you might get an infinite loop. Avoid it! It's very bad.
29th Oct 2020, 2:06 PM
Dual Core
Dual Core - avatar
+ 4
Booleans are the values you get from comparisons, like 3 > 8, 2 == 2 Booleans can only have 2 different values: True and False. Booleans are the values, which you may use in the parentheses of if and while statements.
27th Oct 2020, 8:06 PM
Seb TheS
Seb TheS - avatar
+ 2
this is helpful thank you
27th Oct 2020, 9:29 PM
Da SplitUpNinja
Da SplitUpNinja - avatar
+ 2
Syntax For if loop If (condition to be checked) { statement -if condition is true} else { statement if condition is false} Syntax for while loop While (condition is true) { Code; Code; }
29th Oct 2020, 5:03 PM
Aishwarya
+ 1
When program reaches an if statement, it checks the boolean value in the parentheses ( ). If the boolean value is True, if statement will run the code located in the curly braces { }. If the boolean value is False, the if statement will do nothing.
27th Oct 2020, 8:15 PM
Seb TheS
Seb TheS - avatar
+ 1
what im stuck on right now is that it wants me to take in multiple inputs but the closest ive gotten is getting it to output the first number and then it stops
28th Oct 2020, 12:22 AM
Da SplitUpNinja
Da SplitUpNinja - avatar
+ 1
this is all sorts of screwy cuz ive been playin around trying to figure it out... what am i missing using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int maxBid = Convert.ToInt32(Console.ReadLine()); int x= 1; while(maxBid < x) { if (maxBid == x) break; Console.Write(x); } } } }
28th Oct 2020, 12:28 AM
Da SplitUpNinja
Da SplitUpNinja - avatar
+ 1
probably closest ive gotten but it just repeats the 1st input using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int maxBid = Convert.ToInt32(Console.ReadLine()); int x= 1; while(x < maxBid) { if (maxBid <= x) break; Console.Write(maxBid); x++; } } } }
28th Oct 2020, 12:42 AM
Da SplitUpNinja
Da SplitUpNinja - avatar
+ 1
think im getting closer... now i get multiple inputs... using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int x= 1; while(true) { int maxBid = Convert.ToInt32(Console.ReadLine()); {if (maxBid <= x) break; Console.Write(maxBid); } } } } }
28th Oct 2020, 12:56 AM
Da SplitUpNinja
Da SplitUpNinja - avatar
0
Do you understand booleans?
27th Oct 2020, 6:23 PM
Seb TheS
Seb TheS - avatar
0
i dont believe ive gotten that far yet ive been using integers and things like that
27th Oct 2020, 7:22 PM
Da SplitUpNinja
Da SplitUpNinja - avatar
0
bout halfway through conditionals and loops
27th Oct 2020, 7:25 PM
Da SplitUpNinja
Da SplitUpNinja - avatar
0
i get the structure of loops, i am just having difficulty finding what i need at the time what im missing
30th Oct 2020, 3:26 PM
Da SplitUpNinja
Da SplitUpNinja - avatar