Logic- Carry out this
set of code WHILE
this condition is
false
While loop
Used when you
are unsure of
long you need
to loop for
Loop is
considered a
"Pre test"
loop
Condition
is checked
before the
loop is
executed
Condition must
be initialized
from before for
this loop to
occur
Logic: While the
counter is not met, DO
the code and update the counter
For loop
Used when you
know how many
iterations you need
in a loop
Loop is
considered a
"Pre test"
loop
Combines loop
control into one
statment.
removes loop
control from
body of loop
Less chance of
messing up
counter options
as is declare
before hadn
Flow control of loops
Counters are used
when we want a
certain piece of code
to occur only a set
number of time.
Counters are used
best with While loops
but can be used with
other loops also
Methods
Code block that
contains many
statements
Three ways of depicting methods
Method signature
Has a type
Brief
description of
what method
does
Has a
name and
parameters
parameters are place holders
[return type] + [name
of
method]+(parameters)
Call to the method
has a name but no type
instead of
parameters (as
placeholders) it
has arguments
[name] +(arguments)
Method Declaration
contains comments
Includes Method signature
contains the "scope" or
body of code within the
method signature
Types of methods
Methods that take no parameters and return nothing
Consone.WriteLine()
Methods that take a parameter but do nothing
Console.Writeline("Hello")
Methods that take no parameters but do something
age
=int.parse(Console.Readline())
Method Overloading
Using a method with
the same name but
different parameters
Useful to distinctly use the
same method with
different data types
Methods that are of
the void type do not
need a return
method
General information
Refactoring is when you
take a existing solution
and change it into a new
solution
Methods must have a
return statement for
them to return a
value. anything after
the return statement
is ignored!
Debugging
Step Into
Used when you want
to see what is
happening inside the
code
Used to check the code flow
Step over
Allows debugger to continue
Used as a high level approach
Arrays
used to store
values
Passed as a
reference
and not as a
whole!
created as such:
int[] numbers = new
int[];
New is a operator
used to create
objects
Length
If Array is filled
then use
array.length;
Two ways of
determining length of
elements in array if its
partially filled
Ask user
for
length
and
store it
Take in values of array
and after each uptake
ask user if they want
to add more , provided
the array is not full