Coding syntax Flashcards
Basic switch statement
switch (variable)
{case “condition” or “value “ assigned to variable:
execution eg. Console.write(x);
break;}
Basic for loop
For (int i=0 ; i (>=, < , ==) top of range; i++)
{}
Basic If statement
If (variable meets condition)
{execution}
else if or else
{execution}
“Break;” in loop
finishes loop
“Continue;” in loop
finishes after that iteration of loop
Declare a basic subroutine
Static void/String name (Int a, Int b)
{ int c= a+b;
Console.Write(c); }
Call basic subroutine
name (parameter a, parameter b)
Declare class variable (global variable)
static datatype name=x;
Generate a random number between a and b.
Random rnd = new Random();
r1=rnd.Next(a,b+1);
Declare a basic array
Datatype [] name = new Datatype [i]
where i is no. values.
Add the values 7 and 9 to the array Numbers in the 1st and 2nd positions.
numbers [0]=7
numbers[1]=9
Declare a new list
Lists <datatype> name;
name = new List <datatype.();</datatype>
Add item to a list
name.Add(“x”);
Remove value from a list
name.Remove(“x”);
No. Items in a list
name.Count;