Creating Variables

Prev Next

Overview

B4P requires no variable declarations. Variables are created at their first assignments. The type may change dynamically. It is allowed to assign a number, and later on a value of a different type. This may however be restricted if protection settings are applied.

  a[] = 123;
  a variable[] = 456;
  a   variable[] = 789;   // redundant spaces collapse to 1 space if not put in quotation marks
  "Total Value [€]"[] = 98.95;

  b[] = City;
  (b[])[] = Milano; // Write access: Don't forget the parentheses in LHS expressions
  
  echo( a[] );
  echo( a  variable[] );
  echo( "Total Value [€]"[] );
  echo( b[] ); // City
  echo( City[], ' and ', b[][] ); // 2 x Milano

  b[] = 555.55; // Contained 'City' before.  Assign a number.
  echo( b[] ); // 555.55
123
789
98.95
City
Milano and Milano
555.55
Try it yourself: Open LAN_Features_Creating_Variables.b4p in B4P_Examples.zip. Decompress before use.