11VariablesScope

11VariablesScope - Variables and scope Comp106 Variables...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Variables and scope Comp106 Variables and Scope • Each variable and parameter has a scope . • Scope is the visibility for a variable or parameter. • Helps us reuse variable names.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
void Forward(int time) { OnFwd(OUT_A+OUT_C); Wait(time); Float(OUT_A+OUT_C); } task main() { int time; SetSensor(SENSOR_1, SENSOR_TOUCH); SetTimer(0, 0); while (SENSOR_1 == 0) { Forward(1); } time = Timer(0); SetUserDisplay(time, 1); until (false); } No conflict void ConvertTime(int time) { time = time * 100; } task main() { int length = 2; ConvertTime(length); Forward(length); SetUserDisplay(length, 1); until (false); } How long? Pass By Value
Background image of page 2
Pass By Reference void ConverTime(int &time) { time = time * 100 } task main() { int length = 2; ConvertTime(length); Forward(length); SetUserDisplay(length, 1); until (false); } Local and Global Variables • In NQC, we use “int <varname>” to declare a variable. • If we declare a variable inside the main task or
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

11VariablesScope - Variables and scope Comp106 Variables...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online