0% found this document useful (0 votes)
6 views2 pages

M

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

M

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//Constructor_in_solidity

// SPDX-License-Identifier: MIT
pragma solidity >= 0.5.0 < 0.9.0;
contract local {
uint public count;
constructor(uint new_count) {
count=new_count;
}
}

//if_else_in_solidity

// SPDX-License-Identifier: MIT
pragma solidity >= 0.5.0 < 0.9.0;
contract array {
function check(int a) public pure returns (string memory) {
string memory value;
if (a>0) {
value="Greater than zero";
}
else if (a==0) {
value="Equal to zero";
}
else {
value="Less than zero";
return value;
}
}
}

//loops_in_solidity

// SPDX-License-Identifier: MIT
pragma solidity >= 0.5.0 < 0.9.0;
contract loops {
uint[3] public arr;
uint public count;
function whileloop() public
{
while (count < arr.length)
{
arr[count]=count;
count++;
}
}
function forloop() public {
for (uint i=count; i<arr.length; i++) {
arr[count]=count;
count++;
}
}
}

// Simple Public function

pragma solidity >= 0.5.0 < 0.9.0;


contract local {
uint age=10;
function getter() public view returns(uint) {
return age;
}
function setter() public {
age=age+1;
}
}

// CURD Operation in Solidity

pragma solidity ^0.5.0;


contract Crud {
struct User {
uint id; string
name;
}
User[] public users; uint
public nextId = 0;

function Create(string memory name) public {


users.push(User(nextId,name)); nextId++;
}
function Read(uint id) view public returns(uint, string memory) {for(uint
i=0;i<users.length;i++){
if(users[i].id == id) { return(users[i].id, users[i].name);
}
}
}
function Update(uint id, string memory name) public {
for(uint i=0;i<users.length; i++) {
if(users[i].id == id) {
users[i].name = name;
}
}
}
function Delete(uint id) public {delete users[id];
}
function find(uint id) view internal returns(uint) {for(uint
i=0;i<users.length;i++){
if(users[i].id == id) {
return i;
}
}
}
}

You might also like