Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Short recap on Variables and intro to functions

Variables are placeholders for different values like x=1,


carcolor=”red”,runningspeed=20
Functions/methods require an input to create an output

public static int Add(int a, int b)


{
return a + b;
}
...
Console.WriteLine(Add(5, 10))

Static makes a function usable across scripts(universal)


If and else statements
If statements try to compare variables with our given
conditions; when these conditions are met, the code will
be executed.

if(int a == int b)
{
Console.WriteLine(“a is equal b”);
}
else
{
Console.WriteLine(“a is not equal to b”);
}
Think of if statements functioning like, if this is the
case then do this; else statements meanwhile catch
overlooked problems like “otherwise”. When both are used
like the one below we can translate it to: If a is equal
to b then say a is equal to b, otherwise (else) say a is
not equal to b.

if(int a == int b)
{
Console.WriteLine(“a is equal to b”);
}
else
{
Console.WriteLine(“a is not equal to b”);
}
While and for loops pt.1
When we want to keep doing something again and again
and again without having to write if(if(if(if())))
multiple times. Loops help us make loops (crazy).

While loops: For loops:


While this Given a condition
condition is not and number i repeat
met, repeat the function i times
functions inside

tip: loops can be used to add letters as well.


While and for loops pt.2 While-loops:

While loops continue until the condition is satisfied

int count = 1;

while (count <= 5)


{
Console.WriteLine(“number:”+ count);
count++;
}

While loops and for loops accomplish the same thing(lol)


While and for loops pt.3 For-loops:

for(int i = 1; i <= 5; i++)


{
Console.WriteLine(“number:”+ i);
}

To read a For-loop statement we first interpret that


“int i = 1;” is the same as creating a new integer
with the name i. “i <= 5” refers our condition placed.
“i++” is the increment added to i each time the code
repeats.
While and for loops pt.4 loops:

Although while-loops and for-loops accomplish similar


things, there are still advantages in using one over
another in certain parts of your code! We use // to
comment a
/* For example: We can have multiple while- line in our
loops that can all do different things code, while
while still being synchronized, meanwhile a
/* ... */ is
for-loop can only do this function at a
used to
certain point and no-where else which also
enclose a
gives it an advantage in not being variable
dependent commented
*/ part.
Conditional Statements Summary:
for(var condition;
If (condition is true) {
While loops:
while condition is
then do this;
false; +/- until true)
} else {
{
do something else;
do this;
}
}
if and else for-loop

var condition;
while(condition is not true)
{
do this; I dont know
} what to put
while-loop here lol.

You might also like