While/if/ loops help | SoloLearn: Learn to code for FREE!

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

10/27/2020 5:38:37 PM

Da SplitUpNinja

14 Answers

New Answer

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

+7

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.

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

+2

this is helpful thank you

+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; }

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

+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

+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); } } } }

+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++; } } } }

+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); } } } } }

0

Do you understand booleans?

0

i dont believe ive gotten that far yet ive been using integers and things like that

0

bout halfway through conditionals and loops

0

i get the structure of loops, i am just having difficulty finding what i need at the time what im missing