നിയന്ത്രണം#

ആമുഖം#

നിയന്ത്രണത്തിൽ ടൈമിംഗ്, പ്രോഗ്രാം ഫ്ലോ, കണ്ടീഷണൽ ലോജിക്, പ്രോജക്റ്റ് ടെർമിനേഷൻ എന്നിവയ്ക്കുള്ള ഫംഗ്‌ഷനുകൾ ഉൾപ്പെടുന്നു. ഈ നിയന്ത്രണങ്ങൾ നിങ്ങളെ എക്സിക്യൂഷൻ താൽക്കാലികമായി നിർത്താനും, ലൂപ്പുകൾ സൃഷ്ടിക്കാനും, ലോജിക് പാത്തുകൾ നിർവചിക്കാനും, ഒരു പ്രോഗ്രാം അവസാനിപ്പിക്കാനും അനുവദിക്കുന്നു.

പ്രവർത്തനങ്ങളും കീവേഡുകളും#

API ഫംഗ്ഷനുകളും C++ കീവേഡുകളും ഉൾപ്പെടെ ലഭ്യമായ നിയന്ത്രണങ്ങളുടെ ഒരു ലിസ്റ്റ് താഴെ കൊടുക്കുന്നു:

  • wait – ഒരു നിശ്ചിത സമയത്തേക്ക് പ്രോജക്റ്റ് താൽക്കാലികമായി നിർത്തുന്നു.

  • for – Repeats a block of code a set number of times.

  • if – ഒരു വ്യവസ്ഥ ശരിയാണെങ്കിൽ കോഡിന്റെ ഒരു ബ്ലോക്ക് പ്രവർത്തിപ്പിക്കുന്നു.

  • if/else – ഒരു വ്യവസ്ഥ ശരിയാണെങ്കിൽ ഒരു ബ്ലോക്ക് കോഡ് പ്രവർത്തിപ്പിക്കുന്നു, അല്ലെങ്കിൽ തെറ്റാണെങ്കിൽ മറ്റൊരു ബ്ലോക്ക് പ്രവർത്തിപ്പിക്കുന്നു.

  • if/else if/else – ഒന്നിലധികം അവസ്ഥകൾ ക്രമത്തിൽ പരിശോധിച്ച്, ആദ്യത്തെ അവസ്ഥ ശരിയായ ബ്ലോക്ക് പ്രവർത്തിപ്പിക്കുന്നു.

  • while – ഒരു വ്യവസ്ഥ ശരിയായിരിക്കുമ്പോൾ ഒരു കോഡ് ബ്ലോക്ക് ആവർത്തിക്കുന്നു.

  • break – നിലവിലെ ലൂപ്പിൽ നിന്ന് ഉടൻ പുറത്തുകടക്കുന്നു.

  • programStop – പ്രോജക്റ്റ് ഉടൻ അവസാനിപ്പിക്കുന്നു.

wait#

അടുത്ത കോഡ് വരിയിലേക്ക് പോകുന്നതിന് മുമ്പ് ഒരു നിശ്ചിത സമയത്തേക്ക് പ്രോജക്റ്റ് താൽക്കാലികമായി നിർത്തുന്നു.

Available Functions
void wait(
  double time,
  timeUnits units );

Parameters

പാരാമീറ്റർ

ടൈപ്പ് ചെയ്യുക

വിവരണം

time

double

പോസിറ്റീവ് double ആയി കാത്തിരിക്കേണ്ട സമയം.

units

timeUnits

സമയം പ്രതിനിധീകരിക്കുന്നതിനുള്ള യൂണിറ്റ്: msec (സ്ഥിരസ്ഥിതി) – മില്ലിസെക്കൻഡ് അല്ലെങ്കിൽ seconds

Return Values

ഈ ഫംഗ്ഷൻ ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Examples
// Stop driving after 1 second
Drivetrain.drive(forward);
wait(1, seconds);
Drivetrain.stop();

for#

ഒരു കോഡ് ബ്ലോക്ക് ആവർത്തിക്കുന്നു. എണ്ണൽ ഫോം ഒരു നിശ്ചിത എണ്ണം തവണ പ്രവർത്തിക്കുന്നു; ശ്രേണി അടിസ്ഥാനമാക്കിയുള്ള ഫോം ഒരു ശേഖരത്തിലെ ഓരോ ഇനത്തിനും ഒരു തവണ പ്രവർത്തിക്കുന്നു.

Syntax

1 — കൗണ്ടിംഗ് ലൂപ്പ് — ഒരു നിശ്ചിത എണ്ണം തവണ പ്രവർത്തിക്കുന്നു.

for (int i = 0; i < count; i++) {
   // code block
}

2 — ശ്രേണി അടിസ്ഥാനമാക്കിയുള്ള ലൂപ്പ് — ഒരു ശേഖരത്തിലെ ഓരോ ഇനത്തിനും ഒരിക്കൽ പ്രവർത്തിക്കുന്നു.

for (type element : collection) {
   // code block
}

Parameters

പാരാമീറ്റർ

ടൈപ്പ് ചെയ്യുക

വിവരണം

count

int

കോഡ് ബ്ലോക്ക് എത്ര തവണ ആവർത്തിക്കുമെന്നതിന്റെ എണ്ണം.

type

പേര് ടൈപ്പ് ചെയ്യുക

ശേഖരത്തിലെ ഓരോ ഇനത്തിന്റെയും ഡാറ്റ തരം (ഉദാ. int, double).

element

variable

ലൂപ്പിലെ നിലവിലുള്ള ഇനത്തിന്റെ മൂല്യം നിലനിർത്തേണ്ട വേരിയബിളിന്റെ പേര്.

collection

array

ലൂപ്പ് ചെയ്യപ്പെടുന്ന ഇനങ്ങൾ ഉൾക്കൊള്ളുന്ന അറേ (അല്ലെങ്കിൽ വെക്റ്റർ).

Return Values

ഈ നിയന്ത്രണ ഘടന ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Examples
// Drive in a square
for (int i = 0; i < 4; i++) {
  Drivetrain.driveFor(forward, 100, mm);
  Drivetrain.turnFor(right, 90, degrees);
}

// Drive forward different distances
int distances[] = {100, 150, 200};
for (int d : distances) {
  Drivetrain.driveFor(forward, d, mm);
  wait(0.5, seconds);
}

if#

വ്യവസ്ഥ true ആണെങ്കിൽ കോഡിന്റെ അടച്ച ബ്ലോക്ക് പ്രവർത്തിപ്പിക്കുന്നു.

Syntax
if (condition) {
  // code block
}

Parameters

പാരാമീറ്റർ

ടൈപ്പ് ചെയ്യുക

വിവരണം

condition

bool

An expression or variable that is evaluated when the statement runs. If it is true, the code inside the if block runs; if it is false, the block is skipped.

Return Values

ഈ നിയന്ത്രണ ഘടന ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Examples
while (true) {
  if (Brain.Screen.pressing()) {
    // Display a message once the screen is pressed
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
    Brain.Screen.print("Screen pressed!");
    break;
  }
  wait(5, msec);
}

if/else#

വ്യവസ്ഥ true ആണോ അതോ false എന്നതിനെ അടിസ്ഥാനമാക്കി ഏത് എൻക്ലോസ്ഡ് കോഡ് ബ്ലോക്ക് പ്രവർത്തിക്കുന്നുവെന്ന് നിർണ്ണയിക്കുന്നു.

Syntax
if (condition) {
  // code block if true
}
else {
  // code block if false
}

Parameters

പാരാമീറ്റർ

ടൈപ്പ് ചെയ്യുക

വിവരണം

condition

bool

സ്റ്റേറ്റ്മെന്റ് പ്രവർത്തിക്കുമ്പോൾ വിലയിരുത്തപ്പെടുന്ന ഒരു എക്സ്പ്രഷൻ അല്ലെങ്കിൽ വേരിയബിൾ. trueആണെങ്കിൽ, if ബ്ലോക്കിനുള്ളിലെ കോഡ് പ്രവർത്തിക്കുന്നു; falseആണെങ്കിൽ, else ബ്ലോക്കിനുള്ളിലെ കോഡ് പ്രവർത്തിക്കുന്നു.

Return Values

ഈ നിയന്ത്രണ ഘടന ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Examples
while (true) {
  if (Brain.Screen.pressing()) {
    // Turn the screen green when pressed
    Brain.Screen.clearScreen(green);
  } else {
    Brain.Screen.clearScreen();
  }
}

if/else if/else#

ഒന്നിലധികം വ്യവസ്ഥകളെ അടിസ്ഥാനമാക്കി ഏത് അടച്ച കോഡ് ബ്ലോക്കാണ് പ്രവർത്തിക്കുന്നതെന്ന് തിരഞ്ഞെടുക്കുന്നു.

Syntax
if (condition) {
  // code block if first condition is true
}
else if (condition) {
  // code block if second condition is true
}
else {
  // code block if no conditions are true
}

Parameters

പാരാമീറ്റർ

ടൈപ്പ് ചെയ്യുക

വിവരണം

condition

bool

സ്റ്റേറ്റ്മെന്റ് പ്രവർത്തിക്കുമ്പോൾ വിലയിരുത്തപ്പെടുന്ന ഒരു എക്സ്പ്രഷൻ അല്ലെങ്കിൽ വേരിയബിൾ. true എന്ന ആദ്യത്തെ വ്യവസ്ഥ ഏത് ബ്ലോക്ക് പ്രവർത്തിക്കുന്നുവെന്ന് നിർണ്ണയിക്കുന്നു; ഒന്നും trueഅല്ലെങ്കിൽ, else ബ്ലോക്ക് പ്രവർത്തിക്കുന്നു.

Return Values

ഈ നിയന്ത്രണ ഘടന ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Notes
  • if , അവസ്ഥ true.

  • else if checks additional conditions only if all previous conditions are false. Multiple else if statements can be used.

  • else runs its block only if none of the previous conditions are true.

Examples
while (true) {
  // Turn screen blue if pressed on the left half
  if (Brain.Screen.pressing() && Brain.Screen.xPosition() < 240) {
    Brain.Screen.clearScreen(blue);

  // Turn screen green if pressed on the right half
  } else if (Brain.Screen.pressing() && Brain.Screen.xPosition() > 240) {
    Brain.Screen.clearScreen(green);

  } else {
    Brain.Screen.clearScreen();
  }

  wait(20, msec);
}

while#

കൺഡിഷൻ true ആണെങ്കിൽ കോഡ് ആവർത്തിച്ച് പ്രവർത്തിപ്പിക്കുന്നു.

Syntax
while (condition) {
  // code block
}

Parameters

പാരാമീറ്റർ

ടൈപ്പ് ചെയ്യുക

വിവരണം

condition

bool

ഓരോ ആവർത്തനത്തിനും മുമ്പായി വിലയിരുത്തപ്പെടുന്ന ഒരു എക്സ്പ്രഷൻ അല്ലെങ്കിൽ വേരിയബിൾ. അത് trueആണെങ്കിൽ, ലൂപ്പ് തുടരുന്നു; അത് falseആണെങ്കിൽ, ലൂപ്പ് നിർത്തുന്നു.

Return Values

ഈ നിയന്ത്രണ ഘടന ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Notes
  • താഴെയുള്ള ഉദാഹരണങ്ങളിൽ കാണിച്ചിരിക്കുന്നതുപോലെ, വ്യവസ്ഥയ്ക്ക് മുമ്പ് ! ചേർത്തുകൊണ്ട് ഇത് “Wait until” പോലെയും ഉപയോഗിക്കാം.

Examples
while (true) {
  if (Brain.Screen.pressing()) {
    // Turn the screen green whenever it's pressed
    Brain.Screen.clearScreen(green);
  } else {
    Brain.Screen.clearScreen();
  }
}

// Wait until the screen is pressed to turn it green
while (!Brain.Screen.pressing()) {
  wait(20, msec);
}

Brain.Screen.clearScreen(green);

break#

നിലവിലെ ലൂപ്പിൽ നിന്ന് ഉടനടി പുറത്തുകടക്കുന്നു. നെസ്റ്റഡ് ലൂപ്പിലാണെങ്കിൽ, break ഏറ്റവും ഉള്ളിലെ ലൂപ്പിൽ നിന്ന് പുറത്തുകടക്കുന്നു.

Syntax
break;

Parameters

ഈ പ്രസ്താവന ഒരു പാരാമീറ്ററുകളും അംഗീകരിക്കുന്നില്ല.

Return Values

ഈ സ്റ്റേറ്റ്മെന്റ് ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Examples
while (true) {

  // Press the screen to pause on a color
  Brain.Screen.clearScreen(red);
  wait(500, msec);

  if (Brain.Screen.pressing()) {
    break;
  }

  Brain.Screen.clearScreen(green);
  wait(500, msec);

  if (Brain.Screen.pressing()) {
    break;
  }
}

programStop#

ഒരു പ്രോജക്റ്റ് ഉടനടി അവസാനിപ്പിക്കുന്നു.

Syntax
Brain.programStop();

Parameters

ഈ പ്രസ്താവന ഒരു പാരാമീറ്ററുകളും അംഗീകരിക്കുന്നില്ല.

Return Values

ഈ സ്റ്റേറ്റ്മെന്റ് ഒരു മൂല്യം തിരികെ നൽകുന്നില്ല.

Examples
while (true) {

  // Press the screen to end the project
  Brain.Screen.clearScreen(red);
  wait(500, msec);

  if (Brain.Screen.pressing()) {
    Brain.programStop();
  }

  Brain.Screen.clearScreen(green);
  wait(500, msec);

  if (Brain.Screen.pressing()) {
    Brain.programStop();
  }
}