Code Examples
Real-world examples showing Cyl Programming Language language features
Array For Loop Combined
array for loop combined - Demonstrates printing and basic output
// Test array indexing with for loops
fn main() -> void {
let values = [10, 20, 30, 40, 50];
// Print each element using for loop and array indexing
for i in 5 {
let element = values[i];
print_int(element);
}
}
Arithmetic Test
arithmetic test - Demonstrates printing and basic output
// Simple arithmetic test
fn main() -> void {
let x = 10;
let y = 5;
let result = x + y * 2;
print(result);
}
Array Test
array test - Demonstrates printing and basic output
// Array creation and indexing example
fn main() -> void {
let numbers = [10, 20, 30, 40, 50];
// Test array indexing - should now work!
let first = numbers[0]; // 10
let third = numbers[2]; // 30
let last = numbers[4]; // 50
print_int(first);
print_int(third);
print_int(last);
}
Print Test
print test - Demonstrates printing and basic output
// Test print functionality with strings and integers
fn main() -> void {
let message = "Hello, World!";
let number = 42;
print(message);
print_int(number);
}
Struct Test
struct test - Demonstrates printing and basic output
// Struct definition and member access example
struct Person {
age: int,
id: int
}
fn main() -> void {
let person = Person { age: 25, id: 1001 };
// Note: This example compiles and runs successfully
// but doesn't produce output (no print statements)
}
Web Request
web request - Demonstrates printing and basic output
// Advanced web request example (aspirational - for future implementation)
import net;
import fs;
fn main() -> void {
// This is a design example showing the intended syntax
// Current implementation supports basic functions, variables, and control flow
// Future implementation would support:
// let response = net.get("https://api.example.com/data");
//
// if response.status == 200 {
// fs.write("/tmp/response.json", response.body);
// print("Data saved successfully");
// } else {
// print("Request failed");
// }
print("Web request functionality is planned for future releases");
}
Hello World
hello world - Demonstrates printing and basic output
// Hello World example in Cyl
fn main() -> void {
print("Hello, World!");
print("Welcome to Cyl programming language!");
}