0
pragma solidity ^0.4.24;

contract sec
{

    uint age= 15;
    uint agePer;

    modifier onlyPer (){

        if(age==agePer)
        {
            _;
        }
    }

    function getage(uint agep) onlyPer() public returns (uint){

        agePer=agep;
        return agePer;
    }
}
  • 1
    How and where exactly does this code "display" anything? – goodvibration Aug 13 '18 at 17:00
0

age is 15, and agePer is 0, so age == agePer is not true. That means the body of getage never runs, and so the return value is always the default uint value of 0.

  • i should pass a constructor to initalize agePer first then execute getage function. – Faheel Sattar Aug 13 '18 at 17:01
  • Also, the code is senseless. Set agePer=agep only if agePer==agep??? – goodvibration Aug 13 '18 at 17:01
  • BTW, the modifier doesn't require nor assert, so I'm not sure that the body of the function never runs (I'm just not sure that it runs at all, because I can't see anyone calling this function to begin with). – goodvibration Aug 13 '18 at 17:02
  • @goodvibration The underscore in a modifier represents the function body. if (false) { _; } means the body of the function isn't executed. – smarx Aug 13 '18 at 17:05
  • Cool, was missing that part in my "vocabulary" (was always happy with the fact that this syntax worked, but never bothered to dive into it). – goodvibration Aug 13 '18 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.